package com.bjtu.restaurantreviews.dao;

import com.bjtu.restaurantreviews.domain.Restaurant;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Chen
 * @Description:
 * @Date: Created in 18:14 2018/5/3
 */
public interface RestaurantRepository extends JpaRepository<Restaurant,Long>,JpaSpecificationExecutor<Restaurant> {
    //根据关键字模糊查询
    @Query(value = "select rname from restaurant  where rname like %?1% or rtype like %?1% or rcity like %?1% order by RStar desc",nativeQuery = true)
//    public ArrayList<Restaurant> findByWord(String word);
    Page<Restaurant> findByWord(String word, Pageable pageable);

    @Query(value = "select * from restaurant where rtype=?1 order by rand() limit 10",nativeQuery = true)
    @Modifying
    public List<Restaurant> recommendtype(String rtype);

    List<Restaurant> findByRid(int rid);
}
